#include<iostream>   
using namespace std;
int mintest(int a, int b);//先定义一个比较大小返回小值的函数；
const int n = 6;
int a[n] = { 1, 5, 10, 20, 50, 100 };//该数组为不同种类币值
int b[n] = { 1, 5, 10, 20, 50, 100 };//该数组为各种币值所拥有的个数
int txsf(int money)
{
    int num = 0;
    if (money > 100)
    {
        for (int i = n - 1; i >= 0; i--)      
        {
            int c = mintest((money / a[i]), b[i]);//c为所取的币值个数
            money = money - c * a[i];
            num += c;
        }
        if (money > 0)
            num = -1;
        return num;
    }
    else if(money>50&&money<100)
    {
        for (int i = n - 2; i >= 0; i--)
        {
            int c = mintest(money / a[i], b[i]);//c为所取的币值个数
            money = money - c * a[i];
            num += c;
        }
        if (money > 0)
            num = -1;
        return num;
    }
    else if (money > 20 && money < 50)
    {
        for (int i = n - 3; i >= 0; i--)
        {
            int c = mintest(money / a[i], b[i]);//c为所取的币值个数
            money = money - c * a[i];
            num += c;
        }
        if (money > 0)
            num = -1;
        return num;
    }
    else if (money > 10 && money < 20)
    {
        for (int i = n - 4; i >= 0; i--)
        {
            int c = mintest(money / a[i], b[i]);//c为所取的币值个数
            money = money - c * a[i];
            num += c;
        }
        if (money > 0)
            num = -1;
        return num;
    }
    else if(money > 1 && money < 10)
    {
        for (int i = n - 5; i >= 0; i--)
        {
            int c = mintest(money / a[i], b[i]);//c为所取的币值个数
            money = money - c * a[i];
            num += c;
        }
        if (money > 0)
            num = -1;
        return num;
    }
    
}
int mintest(int a, int b)
{
    if (a > b)
    {
        return b;
    }
    else if (a == b)
    {
        return a;
    }
    else if(a < b)
    {
        return a;
    }
}

int main()
{
    int money;
    cout << "请输入你要取的钱:";
    cin >> money;
    int zs = txsf(money);
    if (zs != -1)
        cout <<"需要取" <<zs<<"张" << endl;
    else
    {
        cout << "没办法取到"<<money << endl;
    }
    
}